package com.ybl.store.backend.controller;

import com.ybl.store.backend.dto.req.ClerkSaveReqDTO;
import com.ybl.store.backend.dto.req.ClerkUpdateReqDTO;
import com.ybl.store.backend.dto.resp.ClerkPageRespDTO;
import com.ybl.store.backend.dto.resp.ClerkRealNameRespDTO;
import com.ybl.store.backend.dto.resp.ClerkSaveRespDTO;
import com.ybl.store.backend.dto.resp.ListRespDTO;
import com.ybl.store.backend.service.impl.ClerkServiceImpl;
import com.ybl.store.common.convention.result.Result;
import com.ybl.store.common.convention.result.Results;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 店员控制层
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("clerk")
public class ClerkController {
    
    private final ClerkServiceImpl clerkService;

    /**
     * 新增店员
     */
    @PostMapping
    public Result<ClerkSaveRespDTO> saveClerk(@RequestBody ClerkSaveReqDTO requestParam) {
        return Results.success(clerkService.saveClerk(requestParam));
    }

    /**
     * 删除店员
     */
    @DeleteMapping
    public Result<Void> deleteClerkById(@RequestParam("id") Long id) {
        clerkService.deleteClerkById(id);
        return Results.success();
    }

    /**
     * 修改店员
     */
    @PutMapping
    public Result<Void> updateClerk(@RequestBody ClerkUpdateReqDTO requestParam) {
        clerkService.updateClerk(requestParam);
        return Results.success();
    }

    /**
     * 分页查询店员
     */
    @GetMapping("/page")
    public Result<ClerkPageRespDTO> pageClerk(
            @RequestParam("pn") Integer pn,
            @RequestParam("ps") Integer ps,
            @RequestParam(required = false) Long managerId,
            @RequestParam(required = false) String realName)
    {
        return Results.success(clerkService.pageClerk(pn, ps, managerId, realName));
    }

    /**
     * 查询店员名列表
     */
    @GetMapping("/list")
    public Result<ListRespDTO<ClerkRealNameRespDTO>> listClerkRealName(@RequestParam(required = false) Long managerId) {
        return Results.success(clerkService.listClerkRealName(managerId));
    }
}
